package com.csdj.t301.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.sound.midi.Soundbank;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * author:cloud
 * date:2021/3/9 0009
 **/
@Controller
@RequestMapping("/test")
public class IndexController {



    @GetMapping("/index")
    public ModelAndView index(@RequestParam(value="name",required = true)String name,
                              @RequestParam(value = "age",defaultValue = "3")int age
                              ){
        List<String> list = Arrays.asList("a","b","c","d","e");
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("name",name);
        mav.addObject("age",age);
        mav.addObject("list",list);
        return mav;
    }

    @RequestMapping(value = "/welcome/{name}/{age}",method = RequestMethod.GET)
    public ModelAndView welcome(@PathVariable("name") int name,
                                @PathVariable("age") int age){
        System.out.println(name);
        ModelAndView mav = new ModelAndView("welcome");
        mav.addObject("2","");
        mav.addObject("3","ddd“");
        return mav;
    }

    @GetMapping("/error")
    public String error(HttpServletRequest request){
        int c = 1/0;
        return "error";
    }

    @GetMapping("/upload")
    public String upload(){
        return "upload";
    }

//    @ExceptionHandler(value = {Exception.class})
    public ModelAndView hander(Exception e){
        ModelAndView mav = new ModelAndView("error");
        mav.addObject("msg",e.getMessage());
        return mav;
    }

    public static void main(String[] args) {
        float a = 0.3333333f;
        BigDecimal b = new BigDecimal("0.3333333");
        System.out.println(b.multiply(BigDecimal.valueOf(3)).toString());
    }
}
